<?php

class S_Input extends CI_Input {
	
	//修复这个cookie的bug，当config.php中提供$config['cookie_prefix']时
	public function cookie($index = NULL, $xss_clean = FALSE)
	{
		if ($index === NULL AND ! empty($_COOKIE))
		{
			$cookie = array();

			// loop through the full _GET array
			foreach (array_keys($_COOKIE) as $key)
			{
				$cookie[$key] = $this->_fetch_from_array($_COOKIE, $key, $xss_clean);
			}
			return $cookie;
		}
		
		if (isset($_COOKIE[$index]))
		{
			return $this->_fetch_from_array($_COOKIE, $index, $xss_clean);
		}
		else
		{
			return $this->_fetch_from_array($_COOKIE, config_item('cookie_prefix').$index, $xss_clean);
		}
	}
	
	//返回header头信息
	public function header($index = NULL, $xss_clean = FALSE)
	{
		static $_HEADER = NULL;
		if ($_HEADER === NULL)
		{
			$_HEADER = getallheaders(); //这函数只有apache有，已经重写在common.php中
		}
		
		if ($index === NULL AND ! empty($_HEADER))
		{
			$header = array();

			// loop through the full _GET array
			foreach (array_keys($_HEADER) as $key)
			{
				$header[$key] = $this->_fetch_from_array($_HEADER, $key, $xss_clean);
			}
			return $header;
		}
		
		return $this->_fetch_from_array($_HEADER, $index, $xss_clean);
	}
	
}

